package org.blackcat.config;

import org.blackcat.web.filter.BaseInterceptor;
import org.blackcat.web.filter.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;


/**
 * Created by blackcat on 2016/12/22.
 * 额外需要的mvc配置
 */
@Configuration
@EnableTransactionManagement(order = 10086)
public class WebMvcConfig extends WebMvcConfigurerAdapter {

    @Autowired
    BaseInterceptor baseInterceptor;

    @Autowired
    LoginInterceptor loginInterceptor;

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("redirect:/app/index.html");
        super.addViewControllers(registry);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //设置请求响应头
        registry.addInterceptor(baseInterceptor).addPathPatterns("/**");
        //登录验证
        registry.addInterceptor(loginInterceptor).addPathPatterns("/**");
    }
}
